import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-11-02
 * Time: 16:15
 */
public class TestH12 {

    public static int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] f = new int[n];
        int[] g = new int[n];
        int[] ret = new int[n];
        f[0] = g[n-1] = 1;
        for(int i = 1; i < n; i++) {
            f[i] = f[i-1] * nums[i-1];
        }
        for(int i = n-2; i >= 0; i--) {
            g[i] = g[i+1] * nums[i+1];
        }

        for(int i = 0; i < n; i++) {
            ret[i] = f[i] * g[i];
        }

        return ret;
    }

    public static void main(String[] args) {
        int[] num = {1,2,3,4};
        int[] ret = productExceptSelf(num);
        System.out.println(Arrays.toString(ret));
    }
}
